﻿@using UsedBookTradeSystem.Models.Entity;
@using UsedBookTradeSystem.Models.Enum;
@{
    ViewData["Title"] = "Index";
    Layout = "~/Views/Shared/_BackLayout.cshtml";
    int index = 0;
}

<div class="container-fluid flex-grow-1 container-p-y">
    <h4 class="font-weight-bold py-3 mb-0">用户管理</h4>

    <div class="card">
        <div class="card-header">
            <p style="display:inline;vertical-align:middle">用户列表</p>
            @Html.ActionLink("添加", "Add", new { }, new { @class = "btn btn-success deleteBtn", @style = "float:right" })
        </div>
        <table class="table card-table">
            <thead class="thead-light">
                <tr>
                    <th>#</th>
                    <th>用户名称</th>
                    <th>性别</th>
                    <th>电话</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                @foreach (User item in ViewBag.UserList)
                {
                    index++;
                    <tr>
                        <td scope="row" style="vertical-align:middle">@index</td>
                        <td style="vertical-align:middle">@item.UserName</td>
                        <td style="vertical-align:middle">
                            @(
                                item.Gender switch
                                {
                                    GenderEnum.Male => "男",
                                    GenderEnum.Female => "女",
                                    _ => "未知"

                                } 
                            )
                        </td>
                        <td style="vertical-align:middle">@item.Tel</td>
                        <td style="vertical-align:middle">
                            @(
                                item.IsDisabled switch
                                {
                                    true => "被禁用",
                                    false => "可用",
                                    _=>"被禁用"
                                }
                             )
                        </td>
                        <td style="vertical-align:middle">
                            @Html.ActionLink("编辑", "Edit", new { id = item.Id }, new { @class = "btn btn-success " })
                            @if((bool)item.IsDisabled)
                            {
                                @Html.ActionLink("启用", "ChangeStatus", new { id = item.Id }, new { @class = "btn btn-primary " })
                            }
                            else
                            {
                                @Html.ActionLink("禁用", "ChangeStatus", new { id = item.Id }, new { @class = "btn btn-secondary " })
                            }
                        </td>
                    </tr>
                }
                @if (index == 0)
                {
                    <tr>
                        <td colspan="6" style="vertical-align:central;text-align:center;"> 暂无数据 </td>
                    </tr>

                }
            </tbody>
        </table>
    </div>
</div>
